package app;

import common.struct.SensorData;
import common.struct.State;
import common.struct.ConstantEnum.CmdType;
import common.struct.ConstantEnum.SensorMode;
import common.struct.SensorInfo;

import java.util.Map;

public class AppDemo2 extends AbstractApp {
    @Override
    public void configApp() {
        this.appName = "Demo2";
        this.appDescription = "This is Demo2";
    }

    @Override
    public void getMsg(String sensorName, SensorData value) {
        // 因为注册了front传感器，所以每当front有新的数据时便会触发getMsg，
        // 其中channel是sensor名字，msg是sensor数据
        logger.info(String.format("[%s]: getMsg(channel, msg) -> %s, %s", appName, sensorName, value));
        //用户代码
    }

    public static void main(String[] args) {
        AppDemo2 demo = new AppDemo2();
        AppRemoteConnector connector = AppRemoteConnector.getInstance();
        connector.connectPlatform("127.0.0.1", 9090);
        connector.registerApp(demo);

        Map<String, SensorInfo> supportedSensors = connector.getSupportedSensors();
        if (supportedSensors.containsKey("GreenCar") && supportedSensors.get("GreenCar").state == State.ON) {
            connector.registerSensor("GreenCar", SensorMode.PASSIVE, 1);
        }
        connector.getMsgThread(CmdType.START);
        while (true);
    }
}
